package com.atguigu.my.chapter02

/**
 *
 * @description: xxx
 * @time: 2020-05-22 11:26
 * @author: baojinlong 
 **/
object FunctionDemo {
  def main(args: Array[String]): Unit = {
    val dog = new Dog()
    // 方法转函数,没有形参的时候可以空格加_,如果有形参可以直接写成方法名称就好.
    val function: (Int, Int) => Int = dog.sum
    val my: () => Int = dog.sum2 _
    my()
    println("获取到结果是" + function(1, 2))
    val myFunction = (n1: Int, n2: Int) => {
      n1 + n2
    }
    println(3.isInstanceOf[Int])
    println("获取到结果是" + myFunction(1, 2))
  }
}

class Dog {
  def sum(n1: Int, n2: Int): Int = {
    n1 + n2
  }

  def sum2(): Int = {
    println("我是无参函数")
    3
  }
}
